﻿@model IEnumerable<Treinamento2015_01.Models.StockViewModel>

@{
    ViewBag.Title = "Index";
    Double total = 0;
    foreach (var item in Model)
    {
        total += item.quantity * Convert.ToDouble(item.Product.Price);
    }
}

<h2>Stock</h2>

<p>
    @using (Ajax.BeginForm("ButtonClicked", "Stock", null, new AjaxOptions { HttpMethod = "POST", OnSuccess = "reportCompleted", OnBegin = "loading" }))
    {
        @Html.DropDownList("IdProduct", (IEnumerable<SelectListItem>)ViewBag.Products, Treinamento2015_01.Resources.General.Resource.Select, htmlAttributes: new { @class = "form-control" })
        <label>Quantity: </label><input type="number" id="quantityTo" class="form-control">
        <input type="submit" id="add" value="Add" />
        <input type="submit" id="delete" value="Delete" />
    }
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Product.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.quantity)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Product.Price)
        </th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.ActionLink(item.Product.Name, "../Product/Details", new { id = item.Product.Id })
            </td>
            <td>
                @Html.DisplayFor(model => item.quantity)
            </td>
            <td>
                @("R$" + item.TotalValue.ToString())
            </td>
        </tr>
    }
    <tr>
        <td></td>
        <td></td>
        <td style="border-top: thin solid; border-right: thin solid; border-left: thin solid; border-bottom: thin solid;">
            @("Sum of all Stocks: R$" + ViewBag.TotalSum.ToString())
        </td>
    </tr>
</table>

